﻿using System;
using System.Data;
using BoutiquePOS.DAL.DAO;

namespace BoutiquePOS.DAL.Gateway
{
    /// <summary>
    /// Summary description for RoleDAL
    /// </summary>
    public class RoleDAL:DbGateway
    {
        public void CreateaRole(Role role)
        {
            try
            {
                ConnectionObj.Open();
                string insert = String.Format("Insert Into Role Values(@RoleName)");
                CommandObj.CommandText = insert;
                CommandObj.Parameters.Clear();
                CommandObj.Parameters.Add("@RoleName", SqlDbType.VarChar);
                CommandObj.Parameters["@RoleName"].Value = role.RoleName;
                CommandObj.ExecuteNonQuery();

            }
            catch (Exception)
            {
                throw new Exception("Database Error");
            }
            finally
            {
                if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
                {
                    ConnectionObj.Close();
                }
            }


        }
        public void UpdateaRole(Role role)
        {
            try
            {
                ConnectionObj.Open();
                string update = String.Format("Update Role SET RoleName='{0}' Where RoleId='{1}' ",role.RoleName,role.RoleId);
                CommandObj.ExecuteNonQuery();


            }
            catch (Exception)
            {
                throw new Exception("Database Error");
            }
            finally
            {
                if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
                {
                    ConnectionObj.Close();
                }
            }
        }
    }
}